package com.itheima.tlias84.config;

import com.aliyun.oss.OSS;
import com.aliyun.oss.OSSClientBuilder;
import jakarta.annotation.Resource;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * 使用@Bean 注解自动 自动装配阿里云Oss对象，实现阿里云连接对象的复用
 */
@Configuration
public class LoadOssConfig {

    @Resource
    AliyunOssConfig config;

    /**
     * 创建阿里云oss连接信息OssBean
     * @return
     */
    @Bean("ossBean")
    public OSS createOss(){
        OSS build = new OSSClientBuilder().build(
                config.getEndpoint(),
                config.getAccessKeyId(),
                config.getAccessKeySecret());

        return build;
    }
}
